package edu.java.texbooks.scjp.threads.test04.mailbox.rough;

public class Consumer extends Thread {
	private Mailbox myMailbox;
	private static final int TIME_INTERVAL = 50;

	public Consumer(Mailbox mailbox) {
		myMailbox = mailbox;
	}

	@Override
	public void run() {
		while (true) {
			if (myMailbox.request == true) {
				System.out.println("Consumer prints: " + myMailbox.message);
				myMailbox.request = false;
			}

			try {
				Thread.sleep(TIME_INTERVAL);
			} catch (InterruptedException ie) {
				System.out.println("Consumer thread is interrupted.");
			}
		}
	}
}
